package com.reactim.user.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 好友请求实体类
 */
@Data
@Entity
@Table(name = "friend_requests", 
       uniqueConstraints = @UniqueConstraint(columnNames = {"fromUserId", "toUserId"}),
       indexes = {
           @Index(name = "idx_to_user_status", columnList = "toUserId, status"),
           @Index(name = "idx_from_user_status", columnList = "fromUserId, status"),
           @Index(name = "idx_created_at", columnList = "createdAt")
       })
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(callSuper = false)
public class FriendRequest {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(nullable = false)
    private Long fromUserId; // 发送请求的用户ID
    
    @Column(nullable = false)
    private Long toUserId; // 接收请求的用户ID
    
    @Column(length = 200)
    private String message; // 请求消息
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false, length = 20)
    private RequestStatus status = RequestStatus.PENDING;
    
    @Column(length = 200)
    private String rejectReason; // 拒绝原因
    
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    @LastModifiedDate
    @Column(nullable = false)
    private LocalDateTime updatedAt;
    
    @Column
    private LocalDateTime processedAt; // 处理时间
    
    @Column
    private LocalDateTime expiredAt; // 过期时间
    
    /**
     * 好友请求状态枚举
     */
    public enum RequestStatus {
        PENDING("待处理"),
        ACCEPTED("已同意"),
        REJECTED("已拒绝"),
        EXPIRED("已过期"),
        CANCELLED("已取消");
        
        private final String description;
        
        RequestStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
}